﻿<template>
  <div class="table">
    <!--表7桑园套种农作物情况调查表T_MulInterCrops-->
    <div class="divSearch">
      <Row>
        <Col span="24" class="col-margin"> 填报年度：
        <Select v-model="searchModel.FillInYear" placeholder="全部" style="width: 100px" @on-change="getPageData()">
                        <Option value="">全部</Option>
                        <Option :value="item.DictValue" v-for="item in CreateYearList" :key="item.DictValue">{{item.DictText}}</Option>
                    </Select> 时间周期：
        <Select v-model="searchModel.TimesType" placeholder="全部" style="width: 100px" @on-change="getPageData()">
                        <Option value="">全部</Option>
                        <Option :value="item.DictValue" v-for="item in CycleList" :key="item.DictValue">{{item.DictText}}</Option>
                    </Select>
        <Button icon="ios-search" type="ghost" @click="getPageData()" style="margin-left: 5px;background: linear-gradient(to bottom, #64c8ef 0%,#00a2e2 100%);color: #fff;border-radius: 3px;text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.3);">
                        查询
                    </Button>
        <Button icon="ios-download" type="primary" @click="ExcelDown()" class="searchButton" style="float:right;width: 100px;">数据导出</Button>
        <Upload :on-success="handleSuccess" :action="GetPostUrl()" style="float:right;width: 100px;" v-show="ReportStatus <3">
          <Button type="primary" icon="ios-cloud-upload-outline" class="searchButton">数据导入</Button>
        </Upload>            
        <Button icon="ios-cloud-download" type="primary" @click="TmpDown()" class="searchButton" style="width: 100px;">模板下载</Button>
        </Col>
      </Row>
    </div>
    <Row>
      <Col>
      <table class="reptable" >
        <caption>
            <label style="float:left">{{searchModel.FillInYear|omgConvDict('ReportYear')}}表6桑园套种农作物情况调查表</label>
            <label style="float:right">当前状态:
              <span v-if="ReportStatus==0" class="Error">重新填写</span> 
              <span v-else-if="ReportStatus==1" class="NoReport">未填写</span>
              <span v-else-if="ReportStatus==2" class="AlreadyReport">已填写</span>
              <span v-else-if="ReportStatus==3" class="UpReport">已上报</span>
              <span v-else-if="ReportStatus==4" class="Success">审核通过</span>   
              <span v-else class="NoReport">无需填报</span>                
            </label><br/>
        </caption>
      </table>
      <div style="width:100%; overflow:auto;">
        <table class="reptable" >
          <thead>
            <tr>
              <th rowspan="2" style="width:20%">套种作物名称</th>
              <th rowspan="2" style="width:20%">面积（亩）</th>
              <th rowspan="2" style="width:20%">产值（万元）</th>
              <th rowspan="2" style="width:30%">备注</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in dataList">
              <td><Input v-model="item.SortName"></Input></td>
              <td><Input v-model="item.Area"></Input></td>
              <td><Input v-model="item.OutputValue"></Input></td>
              <td><Input v-model="item.Remark"></Input></td>
            </tr>
          </tbody>
        </table>
      </div>
      <div  class="divButton">
        <Button type="primary" @click="save()" :disabled="ReportStatus > 2">保存</Button>
        <Button type="primary" @click="upReport()" :disabled="ReportStatus!=2">上报</Button>
      </div>
      <Alert banner type="error">
         <p style="color:red;">填报说明:</p>
            1、合计面积=马铃薯面积+大豆面积+蚕豆面积+辣椒面积+其它面积
          <br/>2、合计产值=马铃薯产值+大豆产值+蚕豆产值+辣椒产值+其它产值
          <p style="color:red;font-size: 16px;padding-top: 10px;">特别注意：若指标项没有数据，请直接填“0”</p>
          <span slot="desc"></span>
      </Alert>
      </Col>
    </Row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ZWList: [],
      ReportStatus: 0,
      TotalArea:0,
      TotalOutputValue:0,
      ReportId: "",
      CurrentYear: this.GetCurrentYear(), //当前年度
      TableCodeList: this.GetGroupDict("ReportTableName"), //表名称
      CreateYearList: this.GetGroupDict("ReportYear"), //上报年份
      CycleList: this.GetGroupDict("ReportCycle"), //周期
      showType: false, //编辑框弹出状态
      //查询模型：根据需求删除不不要查询条件
      searchModel: {
        ReportCode: "MulInterCrops",
        FillInYear: "",
        TimesType: "",
        AreaCode: "",
        PageNumber: 1,
        PageSize: 20
      },
      dataList: [] //table数据对象
    };
  },
  mounted() {},
  methods: {
    //数据上报
    upReport() {
      var self = this;
      self.$Modal.confirm({
        title: "提示信息",
        content: "<p>是否确认上报？</p>",
        onOk: () => {
          var model = new Object();
          model.Id = this.ReportId;
          model.reportType = "3";
          model.strMsg = "";
          this.$http.post("Report/PostUpStatus", model).then(function(res) {
            if (res.data.status == 1) {
              self.$Notice.success({
                title: "已上报！",
                desc: false
              });
              self.getPageData();
            } else {
              self.$Modal.error({
                title: "提示信息",
                content: "数据上报失败!!!"
              });
            }
          });
        }
      });
    },
    //获取this.datas: {},//table数据对象
    getPageData() {
      var self = this;
      var user = this.GetlocaStorage("CSuserinfo");
      this.searchModel.AreaCode = user.AreaCode;
      if (self.searchModel.FillInYear != null &&self.searchModel.FillInYear != "") {
        self.searchModel.FillInYear = self.searchModel.FillInYear; //获取当前系统年份
      } else {
        self.searchModel.FillInYear = self.CurrentYear + "年"; //获取填报年度-----数据字典值
      }
      self.$http.post("MulInterCrops/PostAllList", this.searchModel).then(
        function(res) {
          if (res.data.status === 1) {
            self.ReportStatus = res.data.model.Status * 1;
            self.ReportId = res.data.model.ReportId;
            self.dataList = res.data.model.ResultList;
          } else {
            self.$Modal.error({
              title: "提示信息",
              content: res.data.message
            });
          }
        }
        );
    },
    //保存方法
    save() {
      var self = this;
      var model = new Object();
      model.ResultList = this.dataList;
      model.ReportId = this.ReportId;
      this.$http.post("MulInterCrops", model).then(function(res) {
        if (res.data.status == 1) {
          self.getPageData();
          self.$Notice.success({
            title: "保存成功！",
            desc: false
          });
        } else {
          self.$Modal.warning({
            title: "提示信息",
            content: "更新失败,请与管理员联系!"
          });
        }
      });
    },
    //模板下载
    TmpDown: function() {
      window.open(
        this.$http.defaults.baseURL +
          "Report/GetTemplateData?ReportCode=" +
          this.searchModel.ReportCode
      );
    },
    //导入
    GetPostUrl(ReportId) {
      var url =
        this.$http.defaults.baseURL +
        "Report/PostImportDataTwo?ReportId=" +
        this.ReportId +
        "&&ReportCode=" +
        this.searchModel.ReportCode;
      return url;
    },
    handleSuccess() {
      this.getPageData();
      this.$Notice.success({
        title: "数据导入成功！",
        desc: false
      });
    },
    //导出
    ExcelDown: function() {
      var self = this;
      window.open(
        this.$http.defaults.baseURL +
          "MulInterCrops/GetExcelData?ReportId=" +
          this.ReportId +
          "&&ReportName=" +
          this.searchModel.ReportCode
      );
    }
  },
  //创建Vue页面方法
  created: function() {
    //创业Vue前调用获取this.datas: {},//table数据对象
    this.getPageData();
    //this.editInfo();
  },
  watch: {}
};
</script>